home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / bootdat1.zip / BOOTDATE.PAS < prev   
Pascal/Delphi Source File  |  1990-03-25  |  5KB  |  180 lines

  1. program BootDate;
  2. {
  3.   This program serves a number of functions:
  4.  
  5.   1. Logging all system boots
  6.   2. Monitoring disk space
  7.   3. Reminding you when a backup was last performed
  8.   4. Displaying the current date and time
  9.  
  10.   It outputs a line on the screen in the following format
  11.  
  12.   Date time C: D: Interval
  13.  
  14.   e.g.
  15.  
  16.   24-03-1990 08:50p 810k 2.05Mb 5 days
  17.  
  18.   where C: is the free space on drive C:, D: is the free space on drive D:,
  19.   and Interval is the time since the last backup. This output is logged to
  20.   a file called C:\BOOTDATE.LOG. If this file does not exist it is created.
  21.   The date of the last backup is determined from the date stamp of a file.
  22.   The default name for this file is C:\BACKUP.DAT however an alternative
  23.   may be specified on the command line: BOOTDATE \TAPE\STREAM.LOG for e.g.
  24.   If your backup procedure does not already involve the creation of a date
  25.   stamped file you will need to amend it
  26.  
  27.   The program relies on DOS 3.x functionality for formatting dates in a
  28.   country dependent manner and should not be run using earlier versions of
  29.   DOS. Turbo Professional is required to recompile this program.
  30.  
  31.   Paul O'Nolan CIS 72007,242
  32.  
  33.   Helmstraat 28, The Hague 2584 AT, Netherlands
  34. }
  35. Uses
  36.      TpCrt, TpDate, Dos, TpDos;
  37. Var
  38.      DateStamp,
  39.      Bootline,
  40.      FreeSpaceList,
  41.      DriveCspace,
  42.      DriveDspace,
  43.      BackupDate,
  44.      BackupInterval,
  45.      DateAndTime,
  46.      DateFormat,
  47.      TimeFormat            : string;
  48.  
  49.      Julian1,
  50.      Julian2               : date;     {type defined in TpDate}
  51.  
  52.      Logfile               : text;
  53.  
  54.  
  55. procedure GetFreeSpaceOn(DriveToCheck: byte; var FreeSpaceDrive: string);
  56. var
  57.      ClustersAvailable,
  58.      TotalClusters,
  59.      BytesPerSector,
  60.      SectorsPerCluster     : word;
  61.  
  62.      BytesPerCluster,
  63.      DiskCapacity,
  64.      FreeSpace             : longint;
  65.  
  66. begin
  67.   if GetDiskInfo(DriveToCheck,
  68.                  ClustersAvailable,
  69.                  TotalClusters,
  70.                  BytesPerSector,
  71.                  SectorsPerCluster) then
  72.     begin
  73.       BytesPerCluster := LongInt(SectorsPerCluster) * LongInt(BytesPerSector);
  74.       DiskCapacity    := LongInt(TotalClusters)     * BytesPerCluster;
  75.       FreeSpace       := LongInt(ClustersAvailable) * BytesPerCluster div 1024;
  76.  
  77.       if FreeSpace > 1024 then
  78.         begin
  79.           str(FreeSpace / 1024:3:2,FreeSpaceDrive);
  80.           FreeSpaceDrive := FreeSpaceDrive + 'Mb';
  81.         end
  82.       else
  83.         begin
  84.           str(FreeSpace,FreeSpaceDrive);
  85.           FreeSpaceDrive := FreeSpaceDrive + 'k';
  86.         end;
  87.     end
  88.   else FreeSpaceDrive := 'ERR';
  89. end;
  90.  
  91.  
  92. procedure GetLastBackupDate(DateFormat: string);
  93. var
  94.     F:              file;
  95.     L:              LongInt;
  96.     Daystr,
  97.     Monthstr,
  98.     Yearstr:        String;
  99.     DT:             DateTime; {type defined in DOS unit}
  100.     days,
  101.     months,
  102.     years:          Integer;
  103.  
  104. begin
  105.   BackupDate     := DateStamp + ' not found';
  106.   BackupInterval := 'Date of last backup unknown';
  107.  
  108.   if ExistFile(DateStamp) then
  109.     begin
  110.       Assign(F,DateStamp);
  111.       Reset(F);
  112.       GetFTime(F,L);
  113.       Close(F);
  114.       UnPackTime(L,DT);
  115.  
  116.       BackupDate := DMYtoDateString(DateFormat, DT.day, DT.Month, DT.Year);
  117.       Julian2 := DMYtoDate(DT.day, DT.month, DT.year);
  118.       GetDate(DT.year, DT.month, DT.day, DT.min); {min receives dayofweek}
  119.       Julian1 := DMYtoDate(DT.day, DT.month, DT.year);
  120.       DateDiff(Julian1,Julian2,days,months,years);
  121.  
  122.       str(days, daystr);
  123.       str(months, monthstr);
  124.       str(years, yearstr);
  125.  
  126.       case years of
  127.         0: BackupInterval := '';
  128.         1: BackupInterval := yearstr + ' year,  '
  129.         else
  130.           BackupInterval := yearstr + ' years, ';
  131.       end;
  132.  
  133.       if months = 1 then
  134.         BackupInterval := BackupInterval + monthstr + ' month,  '
  135.       else if (years > 0) or (months > 0) then
  136.         BackupInterval := BackupInterval + monthstr + ' months, ';
  137.  
  138.       case days of
  139.         0: if months + years = 0 then
  140.              BackupInterval := 'Today';
  141.         1: BackupInterval := BackupInterval + daystr + ' day ';
  142.         else BackupInterval := BackupInterval + daystr + ' days ';
  143.       end; {case}
  144.  
  145.     end;
  146. end;
  147.  
  148.  
  149. procedure GetDateAndTime;
  150. begin
  151.   DateFormat := InternationalDate(true,false);
  152.   TimeFormat := InternationalTime(false,true,false,false);
  153.   DateAndTime := TodayString(DateFormat)+' '+CurrentTimeString(TimeFormat);
  154. end;
  155.  
  156.  
  157. begin
  158.   if Paramstr(1) = '' then
  159.     DateStamp := 'C:\BACKUP.DAT'
  160.   else DateStamp := ParamStr(1);
  161.  
  162.   GetDateAndTime;
  163.   GetFreeSpaceOn(3,DriveCspace);
  164.   GetFreeSpaceOn(4,DriveDspace);
  165.   GetLastBackupDate(DateFormat);
  166.  
  167.   FreeSpaceList := DriveCspace + ' ' + DriveDspace;
  168.   Bootline      := DateAndTime + ' ' + FreeSpaceList + ' ' + BackupInterval;
  169.  
  170.   Assign(logfile,'C:\BOOTDATE.LOG');
  171.   if ExistFile('C:\BOOTDATE.LOG') then
  172.     Append(logfile)
  173.   else Rewrite(logfile);
  174.  
  175.   Writeln(Bootline);
  176.   Writeln(logfile,Bootline);
  177.  
  178.   Close(logfile);
  179. end.
  180.